#!/bin/bash
# alp-dbrestore: restore incremental database backups
# (C) Copyright 2011 Nicholas Paun. All Rights Reserved.
# Syntax: alp-dbrestore: <database> <backup-directory>

if [[ $1 = "-h" ]]; then
 echo "alp-dbrestore: restore incremental database backups"
 echo "(C) Copyright 2011 Nicholas Paun. All Rights Reserved."
 echo "Syntax: alp-dbrestore: <database> <backup-directory>"
 exit 0
fi

if [[ $# != 2 ]]; then
 $0 -h
 exit 1
fi

PASSWORD="swordfish" #the database password
BACKUPDIR="$2/*" #The backup directory
DATABASE="$1" #the database to restore

mysql -p$PASSWORD -e "CREATE DATABASE IF NOT EXISTS $DATABASE;" #create restore DB if it doesn't exsist

for TABLE in $BACKUPDIR; do 
 mysql -p$PASSWORD $DATABASE < $TABLE
 echo "Restored - $TABLE" 
done
